/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>
#include <map>
#include <cstring>
using namespace std;
struct Student
{
    char name[11];
    char id[11];
} student;
int main_1004_1()
{
    char a[11]={0},b[11]={0};
    int score,N;
    map<int,Student> m;
    scanf("%d",&N);
    for (int i=0;i<N ;++i )
    {
        scanf("%s %s %d",a,b,&score);
        strcpy(student.name,a);
        strcpy(student.id,b);
        m[score]=student;
    }
    printf("%s %s\n",m.rbegin()->second.name,m.rbegin()->second.id);
    printf("%s %s\n",m.begin()->second.name,m.begin()->second.id);
	return 0;
}
